package com.itany.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2022-11-10 15:50
 * Description：<描述>
 */
public class CharacterEncodingFilter implements Filter {

    private  String encoding = null; // 字符编码

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
         encoding = filterConfig.getInitParameter("encoding");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if(encoding != null){
            servletRequest.setCharacterEncoding(encoding);
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
